package com.dexilaonian.adpter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.dexilaonian.R;
import com.dexilaonian.bean.ContentBean;
import com.dexilaonian.utils.ImageLoader;
import com.dexilaonian.utils.Logutil;

import java.util.ArrayList;
import java.util.List;
import java.util.zip.Inflater;

public class GridViewAdapter extends BaseAdapter {
	private Context context;
	private List<ContentBean> list = new ArrayList<ContentBean>();

	public GridViewAdapter(Context context, List<ContentBean> list) {
		this.context = context;
		this.list = list;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list==null? 0:list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		if (convertView == null) {
			viewHolder = new ViewHolder();
			LayoutInflater inflater = LayoutInflater.from(context);
			convertView = inflater.inflate(R.layout.grid, null);
			viewHolder.name = (TextView) convertView.findViewById(R.id.tv_name_store);
			viewHolder.original_price = (TextView) convertView.findViewById(R.id.tv_price);
			viewHolder.iv_store = (ImageView) convertView.findViewById(R.id.grid_store);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		String pic_url = list.get(position).getPic_url();
		viewHolder.name.setText(list.get(position).getName());
		viewHolder.original_price.setText(list.get(position).getOriginal_price());
		ImageLoader.display(context,pic_url,viewHolder.iv_store);
		return convertView;
	}
	class ViewHolder{
		TextView original_price;
		TextView name;
		ImageView iv_store;
	}
}
